package cn.sc.summer.token.handler.server;

import cn.sc.summer.token.util.ResponseUtil;
import cn.sc.summer.constant.model.Result;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

/**
 * 类名：未登录处理
 *
 * @author a-xin
 * @date 2023/11/22 17:25
 */
@Service
public class AuthenticationEntryPointX implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException {
        e.printStackTrace();
        ResponseUtil.writeFailed(response, new HashMap<>(), Result.fail(e.getMessage()));
    }

}
